import java.util.Random;
class oddThread extends Thread{
    int[] nums = null;
    int oddSum = 0;

    public oddThread(int[] nums) {
        this.nums = nums;
    }

    @Override
    public void run() {
        for (int i = 1; i <nums.length ; i+=2) {
            oddSum += nums[i];
        }
    }

    public int getOddSum(){
        return oddSum;
    }
}

class evenThread extends Thread{
    int[] nums = null;
    int evenSum = 0;

    public evenThread(int[] nums) {
        this.nums = nums;
    }

    @Override
    public void run() {
        for (int i = 0; i <nums.length ; i+=2) {
            evenSum += nums[i];
        }
    }

    public int getEvenSum(){
        return evenSum;
    }
}

public class ThreadSum {
    public static void main(String[] args) throws InterruptedException {
        int[] nums = new int[100000];
        Random random = new Random();
        //随机数填充数组
        for (int i = 0; i < nums.length; i++) {
            nums[i] = random.nextInt(100) + 1;
        }
        //获取开始时间戳
        long startTime = System.currentTimeMillis();

        oddThread odd = new oddThread(nums);
        evenThread even = new evenThread(nums);

        odd.start();
        even.start();
        odd.join();
        even.join();

        //获取结束时间戳
        long endTime = System.currentTimeMillis();

        System.out.println("奇数下标和:" + odd.getOddSum());
        System.out.println("偶数下标和:" + even.getEvenSum());
        System.out.println("总和:" + (odd.getOddSum()+even.getEvenSum()));
        System.out.println("消耗时间:" + (endTime - startTime));
    }
}
